<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input id="n" type="text" placeholder="请输入0-100之间的整数">
<input type="button" value="猜一猜" onclick="f()">
<div>结果：<span></span></div>


<script>
    let num = parseInt(Math.random()*101);
    let res = document.querySelector("span");
    let sum = 0;
    function f(){
        let x = document.querySelector("#n");
        let n = parseInt(x.value);
        sum++;
        if (n>num){
            res.innerText = "猜大了";
        }else if (n<num){
            res.innerText = "猜小了";
        }else {
            res.innerText = "猜对了,一共猜了"+sum+"次";

        }
    }

</script>
</body>
</html>